package cn.bdqn.smbms.util;

import org.springframework.core.convert.converter.Converter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StringToDateConverter implements Converter<String, Date> {

    private String pattern;

    public StringToDateConverter(String pattern){
        this.pattern=pattern;
    }


    @Override
    public Date convert(String source) {
        DateFormat df = new SimpleDateFormat(pattern);
        try {
            return df.parse(source);
        }catch (Exception e){
            return null;
        }
    }
}
